<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 
/**
 * 
 * 公用的一些类处理方法
 * @author 66diqiu-li
 *
 */
class Mycommonclass {
	
    /**
     * 
     * 检测表达式
     * @param string $condition
     */
    private static function check_condition($condition)
    {
        return !!preg_match('/^(\S+--\S+--\S+--\S+__)*(\S+--\S+--\S+--\S+)$/', $condition);
    }
    
    /**
     * 
     * 字符串转条件
     * @param $condition
     */
    public static function str2where($condition)
    {
        if(self::check_condition($condition))
        {
            $condition = preg_replace('/^(and|or)/i', '', $condition);
            $condition = str_replace(array('--','__'), array(' ',"' "), $condition);
            $old_char=array(' ne ',' eq ',' lt ',' gt ',' le ',' ge ',' ct ',' nct ');
            $new_char=array(" != '"," = '"," < '"," > '"," <= '"," >= '", " like '%"," not like '%");
            $condition = str_replace($old_char, $new_char, $condition);
            $condition = preg_replace("/\s+(like\s+'[^']+)('|$)/i", " $1%$2", $condition);
            if($condition!='')$condition .= "'";
            return $condition;
        }
        return null;
    }
}